import sys
import pygame


def check_events(**kwargs):
    """
    响应按键和鼠标事件
    :return:
    """
    ship = kwargs.get('ship')
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = True
            elif event.key == pygame.K_LEFT:
                ship.moving_left = True
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_RIGHT:
                ship.moving_right = False
            if event.key == pygame.K_LEFT:
                ship.moving_left = False


# def update_screen(ai_set, screen, ship):
def update_screen(**kwargs):
    ai_set = kwargs.get('settings')
    screen = kwargs.get('screen')
    ship = kwargs.get('ship')
    screen.fill(ai_set.bg_color)  # 背景色
    ship.blitme()
    pygame.display.flip()
